package com.haixin.security.web;

import com.haixin.security.bean.UserRole;
import com.haixin.security.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/user-roles")
public class UserRoleController {
    @Autowired
    private UserRoleService userRoleService;

    @GetMapping
    public List<UserRole> getAllUserRoles() {
        return userRoleService.getAllUserRoles();
    }

    @GetMapping("/{userId}")
    public List<Integer> getRolesByUserId(@PathVariable int userId) {
        return userRoleService.getRolesByUserId(userId);
    }

    @PostMapping
    public boolean addUserRole(@RequestBody UserRole userRole) {
        return userRoleService.addUserRole(userRole);
    }

    @DeleteMapping("/user/{userId}")
    public boolean removeUserRolesByUserId(@PathVariable int userId) {
        return userRoleService.removeUserRolesByUserId(userId);
    }

    @DeleteMapping
    public boolean removeUserRole(@RequestBody UserRole userRole) {
        return userRoleService.removeUserRole(userRole);
    }
}
